package com.terminus.test.multi;

import com.terminus.test.Main;

import java.time.Instant;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Count {
    private static int count;
    private static int limit;
    private static ExecutorService executorService= Executors.newFixedThreadPool(4);
    private static long start;

    public static ExecutorService getExecutorService() {
        return executorService;
    }

    public static void setStart(long start) {
        Count.start = start;
    }

    public static long getStart() {
        return start;
    }

    public synchronized static int getCount() {
        return count;
    }

    public synchronized static void setCount() {
        Count.count++;
        if(count>=limit){
            System.out.println(Date.from(Instant.now()).getTime()-start);
            Main.visitedTest();
            executorService.shutdown();
        }
    }

    public static void setLimit(int limit) {
        Count.limit = limit;
    }
}
